package cn.wizzer.app.web.modules.controllers.cms;

import cn.wizzer.app.cms.modules.services.CmsVideoService;
import cn.wizzer.framework.base.Result;
import com.alibaba.dubbo.config.annotation.Reference;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.nutz.dao.Cnd;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;

@Api(value = "/api/video", tags = "资讯模块")
@At("/api/video")
@IocBean
public class ApiCmsVideoController {
    @Reference
    @Inject
    CmsVideoService videoService;

    @At
    @Ok("json:full")
    public Result list(@ApiParam(required = true)int pageNumber,
                      @ApiParam(required = true)int pageSize) {
        Cnd where = Cnd.where("disabled", "=", 0).and("delFlag", "=", 0);
        return Result.success(videoService.getListPage(pageNumber,pageSize,where.desc("opAt")));
    }

    @At("/detail")
    @Ok("json:full")
    public Result detail(@ApiParam(name = "id",required = true) String id) {
        Cnd where = Cnd.where("id", "=", id);
        return Result.success(videoService.getVideo(where));
    }

    /**
     * 播放结束回调-播放次数验证
     */
    @At
    @Ok("json:full")
    public synchronized Result played(String id) {
        videoService.addPlayTime(id);
        return Result.success();
    }
}
